1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module glib.MemorySlice;
26 
27 private import glib.c.functions;
28 public  import glib.c.types;
29 
30 
31 /** */
32 public T* sliceNew(T)()
33 {
34 	// We cant use sliceAlloc for the GLib array types.
35 	// the actual array structs are larger than the ones used in the API.
36 	static if ( is( T == GArray ) )
37 		return g_array_new(false, false, 1);
38 	else static if ( is( T == GByteArray ) )
39 		return g_byte_array_new();
40 	else static if ( is( T == GPtrArray ) )
41 		return g_ptr_array_new();
42 	else
43 		return cast(T*)g_slice_alloc0(T.sizeof);
44 }
45 
46 public T* sliceAlloc(T)()
47 {
48 	return cast(T*)g_slice_alloc0(T.sizeof);
49 }
50 
51 public T* sliceDup(T)(T* memBlock)
52 {
53 	return cast(T*)g_slice_copy(T.sizeof, memBlock);
54 }
55 
56 public void sliceFree(T)(T* memBlock)
57 {
58 	g_slice_free1(T.sizeof, memBlock);
59 }
60 
61 /**
62  */
63 
64 /**
65  * Allocates a block of memory from the slice allocator.
66  *
67  * The block address handed out can be expected to be aligned
68  * to at least `1 * sizeof (void*)`, though in general slices
69  * are `2 * sizeof (void*)` bytes aligned; if a `malloc()`
70  * fallback implementation is used instead, the alignment may
71  * be reduced in a libc dependent fashion.
72  *
73  * Note that the underlying slice allocation mechanism can
74  * be changed with the [`G_SLICE=always-malloc`][G_SLICE]
75  * environment variable.
76  *
77  * Params:
78  *     blockSize = the number of bytes to allocate
79  *
80  * Returns: a pointer to the allocated memory block, which will
81  *     be %NULL if and only if @mem_size is 0
82  *
83  * Since: 2.10
84  */
85 public void* sliceAlloc(size_t blockSize)
86 {
87 	return g_slice_alloc(blockSize);
88 }
89 
90 /**
91  * Allocates a block of memory via g_slice_alloc() and initializes
92  * the returned memory to 0. Note that the underlying slice allocation
93  * mechanism can be changed with the [`G_SLICE=always-malloc`][G_SLICE]
94  * environment variable.
95  *
96  * Params:
97  *     blockSize = the number of bytes to allocate
98  *
99  * Returns: a pointer to the allocated block, which will be %NULL if and only
100  *     if @mem_size is 0
101  *
102  * Since: 2.10
103  */
104 public void* sliceAlloc0(size_t blockSize)
105 {
106 	return g_slice_alloc0(blockSize);
107 }
108 
109 /**
110  * Allocates a block of memory from the slice allocator
111  * and copies @block_size bytes into it from @mem_block.
112  *
113  * @mem_block must be non-%NULL if @block_size is non-zero.
114  *
115  * Params:
116  *     blockSize = the number of bytes to allocate
117  *     memBlock = the memory to copy
118  *
119  * Returns: a pointer to the allocated memory block, which will be %NULL if and
120  *     only if @mem_size is 0
121  *
122  * Since: 2.14
123  */
124 public void* sliceCopy(size_t blockSize, void* memBlock)
125 {
126 	return g_slice_copy(blockSize, memBlock);
127 }
128 
129 /**
130  * Frees a block of memory.
131  *
132  * The memory must have been allocated via g_slice_alloc() or
133  * g_slice_alloc0() and the @block_size has to match the size
134  * specified upon allocation. Note that the exact release behaviour
135  * can be changed with the [`G_DEBUG=gc-friendly`][G_DEBUG] environment
136  * variable, also see [`G_SLICE`][G_SLICE] for related debugging options.
137  *
138  * If @mem_block is %NULL, this function does nothing.
139  *
140  * Params:
141  *     blockSize = the size of the block
142  *     memBlock = a pointer to the block to free
143  *
144  * Since: 2.10
145  */
146 public void sliceFree1(size_t blockSize, void* memBlock)
147 {
148 	g_slice_free1(blockSize, memBlock);
149 }
150 
151 /**
152  * Frees a linked list of memory blocks of structure type @type.
153  *
154  * The memory blocks must be equal-sized, allocated via
155  * g_slice_alloc() or g_slice_alloc0() and linked together by a
156  * @next pointer (similar to #GSList). The offset of the @next
157  * field in each block is passed as third argument.
158  * Note that the exact release behaviour can be changed with the
159  * [`G_DEBUG=gc-friendly`][G_DEBUG] environment variable, also see
160  * [`G_SLICE`][G_SLICE] for related debugging options.
161  *
162  * If @mem_chain is %NULL, this function does nothing.
163  *
164  * Params:
165  *     blockSize = the size of the blocks
166  *     memChain = a pointer to the first block of the chain
167  *     nextOffset = the offset of the @next field in the blocks
168  *
169  * Since: 2.10
170  */
171 public void sliceFreeChainWithOffset(size_t blockSize, void* memChain, size_t nextOffset)
172 {
173 	g_slice_free_chain_with_offset(blockSize, memChain, nextOffset);
174 }
175 
176 /** */
177 public long sliceGetConfig(GSliceConfig ckey)
178 {
179 	return g_slice_get_config(ckey);
180 }
181 
182 /** */
183 public long* sliceGetConfigState(GSliceConfig ckey, long address, uint* nValues)
184 {
185 	return g_slice_get_config_state(ckey, address, nValues);
186 }
187 
188 /** */
189 public void sliceSetConfig(GSliceConfig ckey, long value)
190 {
191 	g_slice_set_config(ckey, value);
192 }